<template>
  <div class="ue-moudle">
    <script :id=id type="text/plain"></script>
  </div>
</template>
<script>
  import tools from "COMMON/tools.js"

  export default {
    name: 'UE',
    data () {
      return {
        editor: null,
        param: '',
      }
    },
    props: {
      defaultMsg: {
        type: String
      },
      config: {
        type: Object
      },
      id: {
        type: String
      },
    },
    mounted() {
      this.param = tools.getArg('news_id', String(location.href).replace(/[#]*$/g, ""));
      const _this = this;
      this.editor = UE.getEditor(this.id, this.config); // 初始化UE
      this.editor.addListener("ready", function () {
        _this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后，放入内容。
        _this.getArticleHtml();
      });
      console.log("上传这堆错误不用理会，上传接口需自行开发配置");
    },
    methods: {
      getArticleHtml() {
        // this.editor.execCommand("inserthtml",'<p class="jwr-view-bottom">如有侵权请及时联系我们</p>');

        let that = this;
        return new Promise(function(resolve) {
            console.log("that.param:"+that.param)
          if (that.param == undefined) {
            return resolve();
          }
          that.$axios.post('/news/AjaxGetInfo',{
            news_id: that.param
          }).then(res => {
            if (res.status == 200) {
              // that.editor.execCommand("inserthtml",'<p class="jwr-view-bottom">如有侵权请及时联系我们</p>');
              that.editor.execCommand("inserthtml", res.data.news_content);
            }
            resolve(res.data.news_title)
          });
        })
      },
      getUEContent() { // 获取内容方法
        return this.editor.getContent()
      },
      getUEContentTxt() { // 获取纯文本内容方法
        return this.editor.getContentTxt()
      }
    },
    destroyed() {
      this.editor.destroy();
    }
  }
</script>

<style lang="less">
  .ue-moudle {
    #ue1 {
      #edui1_iframeholder {
        min-height: 800px !important;
      }
      // .edui-editor {
      //   .edui-editor-bottomContainer {
      //     display: none;
      //   }
      // }
    }
  }
</style>
